package com.guyou.guguxinge;

import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.cbs.android.component.log.L;
import com.cbs.android.component.share.shareinterface.ShareHandler;
import com.cbs.android.component.share.shareinterface.ShareInterface;
import com.cbs.android.component.share.shareinterface.constant.SharePlatform;
import com.cbs.android.component.share.shareinterface.entity.ImageShareMessage;
import com.cbs.android.component.share.shareinterface.entity.LinkShareMessage;
import com.cbs.android.component.share.shareinterface.entity.TextShareMessage;
import com.cbs.android.component.share.umeng.UMeng;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = MainActivity.class.getName();
    private ShareInterface shareInterface;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        shareInterface = new UMeng(this);
    }

    public void shareText(View view) {
        TextShareMessage message = new TextShareMessage()
                .setContent("this is a 测试字符串");
        shareInterface.share(this, SharePlatform.QQ | SharePlatform.QZone | SharePlatform.Wechat | SharePlatform.WechatMoments, message, shareHandler);
    }

    public void shareLink(View view) {
        LinkShareMessage message = new LinkShareMessage()
                .setContent("this is a 测试链接")
                .setImageUrl("http://o7mbkkhsw.bkt.clouddn.com/13m-3800x1200.png")
//                .setImageUrl("http://7j1wem.com1.z0.glb.clouddn.com/13151280909_1471757984_avatar")
                .setTitle("测试标题")
                .setUrl("http://www.baidu.com");
        shareInterface.share(this, SharePlatform.QQ | SharePlatform.QZone | SharePlatform.Wechat | SharePlatform.WechatMoments, message, shareHandler);
    }

    public void shareLocalLink(View view) {
        LinkShareMessage message = new LinkShareMessage()
                .setContent("this is a 测试链接")
                .setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.huge))
                .setTitle("测试标题")
                .setUrl("http://www.baidu.com");
        shareInterface.share(this, SharePlatform.QQ | SharePlatform.QZone | SharePlatform.Wechat | SharePlatform.WechatMoments, message, shareHandler);
    }

    public void shareImage(View view) {
        ImageShareMessage message = new ImageShareMessage()
                .setImageUrl("http://o7mbkkhsw.bkt.clouddn.com/13m-3800x1200.png");
//                .setImageUrl("http://7j1wem.com1.z0.glb.clouddn.com/13151280909_1471757984_avatar");
        shareInterface.share(this, SharePlatform.QQ | SharePlatform.QZone | SharePlatform.Wechat | SharePlatform.WechatMoments, message, shareHandler);
    }

    public void shareLocalImage(View view) {
        ImageShareMessage message = new ImageShareMessage()
                .setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.huge));
        shareInterface.share(this, SharePlatform.QQ | SharePlatform.QZone | SharePlatform.Wechat | SharePlatform.WechatMoments, message, shareHandler);
    }

    private ShareHandler shareHandler = new ShareHandler() {
        @Override
        public void onSuccess() {
            L.e(TAG, "success");
        }

        @Override
        public void onException(Exception e) {
            L.e(TAG, "", e);
        }

        @Override
        public void onFailure(int i, String s) {
            L.e(TAG, "code: " + i + "\tmessage: " + s);
        }
    };
}
